using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using Framework;

namespace SchemaMonitor
{
    [Serializable()]
    public partial class CNodesArchived : CBaseDynamic, IComparable<CNodesArchived>
    {
        #region Constructors
        //Public (Copy Constructor)
        public CNodesArchived(CNodesArchived original, CDataSrc target)
        {
            //Database Connection
            m_dataSrc = target;

            //Copy fields
            _nodeGuid = original.NodeGuid;
            _nodeTypeId = original.NodeTypeId;
            _nodeUserId = original.NodeUserId;
            _nodeData = original.NodeData;
            _nodeDataIsGz = original.NodeDataIsGz;
            _nodeHashSha = original.NodeHashSha;
            _nodeCreated = original.NodeCreated;
            _nodeUpdated = original.NodeUpdated;
            _nodeDeleted = original.NodeDeleted;
        }

        //Protected (Datareader/Dataset)
        protected CNodesArchived(CDataSrc dataSrc, IDataReader dr) : base(dataSrc, dr) {}
        protected CNodesArchived(CDataSrc dataSrc, DataRow     dr) : base(dataSrc, dr) {}
        #endregion

        #region Default Values
        protected override void InitValues_Auto()
        {
            //Null-Equivalent values (except String.Empty, as nulls tend to be inconvenient for string types)
            _nodeGuid = Guid.Empty;
            _nodeTypeId = int.MinValue;
            _nodeUserId = long.MinValue;
            _nodeData = new byte[]{};
            _nodeDataIsGz = false;
            _nodeHashSha = Guid.Empty;
            _nodeCreated = DateTime.MinValue;
            _nodeUpdated = DateTime.MinValue;
            _nodeDeleted = DateTime.MinValue;
        }
        #endregion

        #region Members
        protected Guid _nodeGuid;
        protected int _nodeTypeId;
        protected long _nodeUserId;
        protected byte[] _nodeData;
        protected bool _nodeDataIsGz;
        protected Guid _nodeHashSha;
        protected DateTime _nodeCreated;
        protected DateTime _nodeUpdated;
        protected DateTime _nodeDeleted;
        #endregion

        #region Properties - Column Values
        //Primary Key Column (ReadOnly)
        public Guid NodeGuid
        {   
            get { return _nodeGuid; } 
            set 
            { 
                if (!m_insertPending && _nodeGuid != value)
                {
                    DataSrc.Update(new CNameValueList("NodeGuid", value), new CWhere(TABLE_NAME, new CCriteria("NodeGuid", _nodeGuid), null));
                    CacheClear();
                }
                _nodeGuid = value;
            }    
        }

        //Table Columns (Read/Write)
        public int NodeTypeId    {   get { return _nodeTypeId; } set { _nodeTypeId = value; }    }
        public long NodeUserId    {   get { return _nodeUserId; } set { _nodeUserId = value; }    }
        public byte[] NodeData    {   get { return _nodeData; } set { _nodeData = value; }    }
        public bool NodeDataIsGz    {   get { return _nodeDataIsGz; } set { _nodeDataIsGz = value; }    }
        public Guid NodeHashSha    {   get { return _nodeHashSha; } set { _nodeHashSha = value; }    }
        public DateTime NodeCreated    {   get { return _nodeCreated; } set { _nodeCreated = value; }    }
        public DateTime NodeUpdated    {   get { return _nodeUpdated; } set { _nodeUpdated = value; }    }
        public DateTime NodeDeleted    {   get { return _nodeDeleted; } set { _nodeDeleted = value; }    }

        //View Columns (ReadOnly)

        #endregion

        #region MustOverride Methods
        //Schema Information
        public const string TABLE_NAME      = "NodesArchived";
        public const string VIEW_NAME       = "";         //Used to override this.ViewName { get }
        public const string ORDER_BY_COLS   = "NodeDeleted DESC";   //See the CompareTo method below (Sql-based sorting should match In-Memory sorting)
        public const string SORTING_COLUMN  = "";
        public override string TableName {    get { return TABLE_NAME; } }
        protected override string OrderByColumns {    get { return ORDER_BY_COLS; } }

        //CompareTo Interface (Default Sort Order)
        public int CompareTo(CNodesArchived other) {   return this.NodeDeleted.CompareTo(other.NodeDeleted) *-1;  }

        //Primary Key Information
        public const string PRIMARY_KEY_NAME = "NodeGuid";
        protected override bool InsertPrimaryKey {  get { return true;    }   }
        protected override string PrimaryKeyName {  get { return PRIMARY_KEY_NAME;    }    }
        protected override object PrimaryKeyValue 
        {
              get { return _nodeGuid; }
              set { _nodeGuid = (Guid)value; }
        }

        //Factory Methods - Object
        protected override CBase MakeFrom(DataRow row)      {   return new CNodesArchived(this.DataSrc, row);  }
        protected override CBase MakeFrom(IDataReader dr)   {   return new CNodesArchived(this.DataSrc, dr);   }

        //Factory Methods - List
        protected override IList MakeList()                 {   return new CNodesArchivedList();               }
        protected override IList MakeList(int capacity)     {   return new CNodesArchivedList(capacity);       }

        //Convert from ADO to .Net
        protected override void ReadColumns(IDataReader dr)
        {
            _nodeGuid = CAdoData.GetGuid(dr, "NodeGuid");
            _nodeTypeId = CAdoData.GetInt(dr, "NodeTypeId");
            _nodeUserId = CAdoData.GetLong(dr, "NodeUserId");
            _nodeData = CAdoData.GetBytes(dr, "NodeData");
            _nodeDataIsGz = CAdoData.GetBool(dr, "NodeDataIsGz");
            _nodeHashSha = CAdoData.GetGuid(dr, "NodeHashSha");
            _nodeCreated = CAdoData.GetDate(dr, "NodeCreated");
            _nodeUpdated = CAdoData.GetDate(dr, "NodeUpdated");
            _nodeDeleted = CAdoData.GetDate(dr, "NodeDeleted");
        }
        protected override void ReadColumns(DataRow dr)
        {
            _nodeGuid = CAdoData.GetGuid(dr, "NodeGuid");
            _nodeTypeId = CAdoData.GetInt(dr, "NodeTypeId");
            _nodeUserId = CAdoData.GetLong(dr, "NodeUserId");
            _nodeData = CAdoData.GetBytes(dr, "NodeData");
            _nodeDataIsGz = CAdoData.GetBool(dr, "NodeDataIsGz");
            _nodeHashSha = CAdoData.GetGuid(dr, "NodeHashSha");
            _nodeCreated = CAdoData.GetDate(dr, "NodeCreated");
            _nodeUpdated = CAdoData.GetDate(dr, "NodeUpdated");
            _nodeDeleted = CAdoData.GetDate(dr, "NodeDeleted");
        }

        //Parameters for Insert/Update    
        protected override CNameValueList ColumnNameValues()
        {
            CNameValueList data = new CNameValueList();
            data.Add("NodeGuid", CAdoData.NullVal(_nodeGuid));
            data.Add("NodeTypeId", CAdoData.NullVal(_nodeTypeId));
            data.Add("NodeUserId", CAdoData.NullVal(_nodeUserId));
            data.Add("NodeData", CAdoData.NullVal(_nodeData));
            data.Add("NodeDataIsGz", CAdoData.NullVal(_nodeDataIsGz));
            data.Add("NodeHashSha", CAdoData.NullVal(_nodeHashSha));
            data.Add("NodeCreated", CAdoData.NullVal(_nodeCreated));
            data.Add("NodeUpdated", CAdoData.NullVal(_nodeUpdated));
            data.Add("NodeDeleted", CAdoData.NullVal(_nodeDeleted));
            return data;
        }
        #endregion

        #region Queries - SelectAll/SelectWhere (inherited methods, cast only)
        //Select Queries - Non-Paged
        public new CNodesArchivedList SelectAll()                                                          {    return (CNodesArchivedList)base.SelectAll();                              }
        public new CNodesArchivedList SelectAll(string orderBy)                                            {    return (CNodesArchivedList)base.SelectAll(orderBy);                       }
        public new CNodesArchivedList SelectWhere(string colName, ESign sign, object colValue)             {    return (CNodesArchivedList)base.SelectWhere(colName, sign, colValue);     }
        public new CNodesArchivedList SelectWhere(CCriteria where)                                         {    return (CNodesArchivedList)base.SelectWhere(where);                       }
        public new CNodesArchivedList SelectWhere(CCriteriaList where)                                     {    return (CNodesArchivedList)base.SelectWhere(where);                       }
        public new CNodesArchivedList SelectWhere(CCriteriaList where, string tableOrJoin)                 {    return (CNodesArchivedList)base.SelectWhere(where, tableOrJoin);          }
        public new CNodesArchivedList SelectWhere(CCriteriaList where, string tableOrJoin, string orderBy) {    return (CNodesArchivedList)base.SelectWhere(where, tableOrJoin, orderBy); }
        [Obsolete("Arbitrary where-clause is not necessary portable or safe from sql injection attacks. Consider using the parameterised query interfaces")]
        public new CNodesArchivedList SelectWhere(string unsafeWhereClause)                                {    return (CNodesArchivedList)base.SelectWhere(unsafeWhereClause);           }
        public     CNodesArchivedList SelectById(Guid nodeGuid)                              {    return (CNodesArchivedList)base.SelectById(nodeGuid);       }
        public     CNodesArchivedList SelectByIds(List<Guid> ids)                        {    return (CNodesArchivedList)base.SelectByIds(ids);                         }

        //Select Queries - Paged
        public new CNodesArchivedList SelectAll(  CPagingInfo pi)                                              {    return (CNodesArchivedList)base.SelectAll(  pi);                              }
        public new CNodesArchivedList SelectWhere(CPagingInfo pi, string name, ESign sign, object value)       {    return (CNodesArchivedList)base.SelectWhere(pi, name, sign, value);           }
        public new CNodesArchivedList SelectWhere(CPagingInfo pi, CCriteria criteria)                          {    return (CNodesArchivedList)base.SelectWhere(pi, criteria);                    }
        public new CNodesArchivedList SelectWhere(CPagingInfo pi, CCriteriaList criteria)                      {    return (CNodesArchivedList)base.SelectWhere(pi, criteria);                    }
        public new CNodesArchivedList SelectWhere(CPagingInfo pi, CCriteriaList criteria, string viewOrJoin)   {    return (CNodesArchivedList)base.SelectWhere(pi, criteria, viewOrJoin);        }
        public     CNodesArchivedList SelectByIds(CPagingInfo pi, List<Guid> ids)            {    return (CNodesArchivedList)base.SelectByIds(pi, ids);                         }

        //Select Queries - Transactional
        public new CNodesArchivedList SelectAll(                                                                                           IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectAll(tx);                                                     }
        public new CNodesArchivedList SelectAll(string orderBy,                                                                            IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectAll(orderBy,                                         tx);    }
        public new CNodesArchivedList SelectWhere(string columnName,               object columnValue,                                     IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectWhere(columnName,              columnValue,          tx);    }
        public new CNodesArchivedList SelectWhere(string columnName,   ESign sign, object columnValue,                                     IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectWhere(columnName,    sign,     columnValue,          tx);    }
        public new CNodesArchivedList SelectWhere(                             CCriteria     criteria,                                     IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectWhere(               criteria,                       tx);    }
        public new CNodesArchivedList SelectWhere(                             CCriteriaList criteria,                                     IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectWhere(               criteria,                       tx);    }
        public new CNodesArchivedList SelectWhere(                             CCriteriaList criteria, string tableOrJoin,                 IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public new CNodesArchivedList SelectWhere(                             CCriteriaList criteria, string tableOrJoin, string orderBy, IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public     CNodesArchivedList SelectById(Guid nodeGuid,                                                              IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectById(nodeGuid,                         tx);    }
        public     CNodesArchivedList SelectByIds(List<Guid> ids,                                                        IDbTransaction tx)  {    return (CNodesArchivedList)base.SelectByIds(ids,                                           tx);    }

        //Select Queries - Stored Procs
        public new CNodesArchivedList MakeList(string storedProcName,                             IDbTransaction txOrNull)    {   return (CNodesArchivedList)base.MakeList(storedProcName,             txOrNull);  }
        public new CNodesArchivedList MakeList(string storedProcName, object[] parameters,        IDbTransaction txOrNull)    {   return (CNodesArchivedList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CNodesArchivedList MakeList(string storedProcName, CNameValueList parameters,  IDbTransaction txOrNull)    {   return (CNodesArchivedList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CNodesArchivedList MakeList(string storedProcName, List<object> parameters,    IDbTransaction txOrNull)    {   return (CNodesArchivedList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CNodesArchivedList MakeList(string storedProcName, int param1,                 IDbTransaction txOrNull)    {   return (CNodesArchivedList)base.MakeList(storedProcName, param1,     txOrNull);  }
        public new CNodesArchivedList MakeList(string storedProcName, string param1,              IDbTransaction txOrNull)    {   return (CNodesArchivedList)base.MakeList(storedProcName, param1,     txOrNull);  }

        //Query Results
        protected new CNodesArchivedList MakeList(DataSet              ds) { return (CNodesArchivedList)base.MakeList(ds);        }
        protected new CNodesArchivedList MakeList(DataTable            dt) { return (CNodesArchivedList)base.MakeList(dt);        }
        protected new CNodesArchivedList MakeList(DataRowCollection  rows) { return (CNodesArchivedList)base.MakeList(rows);      }
        protected new CNodesArchivedList MakeList(IDataReader          dr) { return (CNodesArchivedList)base.MakeList(dr);        }
        protected new CNodesArchivedList MakeList(object           drOrDs) { return (CNodesArchivedList)base.MakeList(drOrDs);    }        
        protected new CNodesArchivedList MakeList(byte[]             gzip) { return (CNodesArchivedList)base.MakeList(gzip);      }
        #endregion

        #region Queries - SelectBy[FK] (user-nominated fk/bool columns)
        //Non-Paged
        public CNodesArchivedList SelectByTypeId(int nodeTypeId)    {    return SelectWhere(new CCriteriaList("NodeTypeId", nodeTypeId));    }
        public CNodesArchivedList SelectByUserId(long nodeUserId)    {    return SelectWhere(new CCriteriaList("NodeUserId", nodeUserId));    }
        public CNodesArchivedList SelectByDataIsGz(bool nodeDataIsGz)    {    return SelectWhere(new CCriteriaList("NodeDataIsGz", nodeDataIsGz));    }

        //Paged
        public CNodesArchivedList SelectByTypeId(CPagingInfo pi, int nodeTypeId)    {    return SelectWhere(pi, new CCriteriaList("NodeTypeId", nodeTypeId));    }
        public CNodesArchivedList SelectByUserId(CPagingInfo pi, long nodeUserId)    {    return SelectWhere(pi, new CCriteriaList("NodeUserId", nodeUserId));    }
        public CNodesArchivedList SelectByDataIsGz(CPagingInfo pi, bool nodeDataIsGz)    {    return SelectWhere(pi, new CCriteriaList("NodeDataIsGz", nodeDataIsGz));    }

        //Count
        public int SelectCountByTypeId(int nodeTypeId)   {   return SelectCount(new CCriteriaList("NodeTypeId", nodeTypeId));     }
        public int SelectCountByUserId(long nodeUserId)   {   return SelectCount(new CCriteriaList("NodeUserId", nodeUserId));     }
        public int SelectCountByDataIsGz(bool nodeDataIsGz)   {   return SelectCount(new CCriteriaList("NodeDataIsGz", nodeDataIsGz));     }

        //Transactional
        public CNodesArchivedList SelectByTypeId(int nodeTypeId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("NodeTypeId", nodeTypeId), tx);    }
        public CNodesArchivedList SelectByUserId(long nodeUserId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("NodeUserId", nodeUserId), tx);    }
        public CNodesArchivedList SelectByDataIsGz(bool nodeDataIsGz, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("NodeDataIsGz", nodeDataIsGz), tx);    }
        #endregion

        #region ToXml
        protected override void ToXml_Autogenerated(System.Xml.XmlWriter w)
        {
            Store(w, "NodeGuid", this.NodeGuid);
            Store(w, "NodeTypeId", this.NodeTypeId);
            Store(w, "NodeUserId", this.NodeUserId);
            Store(w, "NodeData", this.NodeData);
            Store(w, "NodeDataIsGz", this.NodeDataIsGz);
            Store(w, "NodeHashSha", this.NodeHashSha);
            Store(w, "NodeCreated", this.NodeCreated);
            Store(w, "NodeUpdated", this.NodeUpdated);
            Store(w, "NodeDeleted", this.NodeDeleted);
        }
        #endregion

    }
}
